﻿/************************************************************************

   Extended Silverlight Toolkit

   Copyright (C) 2010-2012 Xceed Software Inc.

   This program is provided to you under the terms of the Microsoft Public
   License (Ms-PL) as published at http://extendedsilverlight.codeplex.com/license

   Please purchase a commercial version of this toolkit if you are using
   it in a commercial product. The commercial versions support the project,
   and also include more features for each control, priority support,
   source code, updates, removed watermark, and a proprietary license.

   Visit http://xceed.com and follow @datagrid on Twitter.

  **********************************************************************/

using System;
using Xceed.Silverlight.Data.Stats;
using System.Collections.Generic;

namespace Xceed.Silverlight.Data
{
  internal class GroupDataItem : DataItem
  {
    internal static readonly GroupDataItem Any = new GroupDataItem( new object(), true );

    public GroupDataItem( object data )
      : this( data, true )
    {
    }

    public GroupDataItem( object data, bool isLoaded )
      : base( data, isLoaded )
    {
    }

    #region StatContext Property

    public StatContext StatContext
    {
      get;
      internal set;
    }

    #endregion

    #region ItemCount

    public EstimateInt64 ItemCount
    {
      get;
      internal set;
    }

    #endregion ItemCount

    #region Items

    public IEnumerable<DataPath> Items
    {
      get;
      internal set;
    }

    #endregion Items

    public override int GetHashCode()
    {
      return 1;
    }

    public override bool Equals( object obj )
    {
      GroupDataItem groupDataItem = obj as GroupDataItem;
      if( groupDataItem == null )
        return false;

      // If there is no data, we have to compare the references of DataItems. 
      // The same thing applies to GetHashCode(). This is necessary because two
      // DataItems can be empty only temporarily and must be considered different
      // for the UI (container generator).
      if( !groupDataItem.IsLoaded || !this.IsLoaded )
        return object.ReferenceEquals( groupDataItem, this );

      object myData = this.Data;
      object otherData = groupDataItem.Data;

      return ( ( myData == otherData )
            || ( ( myData != null ) && myData.Equals( otherData ) ) );
    }
  }
}
